using NodeCanvas.Variables;
using UnityEngine;

namespace NodeCanvas.Conditions
{
	[Category("Input")]
	public class CheckMousePick : ConditionTask
	{
		public enum ButtonKeys
		{
			Left = 0,
			Right = 1,
			Middle = 2
		}

		public ButtonKeys buttonKey;

		[LayerField]
		public int layer;

		[BlackboardOnly]
		public BBGameObject saveGoAs;

		[BlackboardOnly]
		public BBFloat saveDistanceAs;

		[BlackboardOnly]
		public BBVector savePosAs;

		private int buttonID;

		private RaycastHit hit;

		protected override string info
		{
			get
			{
				string text = buttonKey.ToString() + " Click";
				if (!string.IsNullOrEmpty(savePosAs.dataName))
				{
					text = text + "\nSavePos As " + savePosAs;
				}
				if (!string.IsNullOrEmpty(saveGoAs.dataName))
				{
					text = text + "\nSaveGo As " + saveGoAs;
				}
				return text;
			}
		}

		protected override bool OnCheck()
		{
			buttonID = (int)buttonKey;
			if (Input.GetMouseButtonDown(buttonID) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, float.PositiveInfinity, 1 << layer))
			{
				saveGoAs.value = hit.collider.gameObject;
				saveDistanceAs.value = hit.distance;
				savePosAs.value = hit.point;
				return true;
			}
			return false;
		}
	}
}
